home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / CMPLTPAS / FLIPFLD.PAS < prev    next >
Pascal/Delphi Source File  |  1988-07-14  |  3KB  |  69 lines

  1. {->>>>FlipField<<<<--------------------------------------------}
  2. {                                                              }
  3. { Filename : FLIPFLD.SRC -- Last Modified 7/14/88              }
  4. {                                                              }
  5. { This routine facilitates entry of "toggle" fields--fields    }
  6. { that have one of only two different values: Male/Female,     }
  7. { Citizen/Non-citizen, etc.  You specify an X,Y position for   }
  8. { the field, a string for each of the True and False case, and }
  9. { an initial Boolean value that specifies which of the two     }
  10. { alternatives will be initially displayed.  Pressing ESC      }
  11. { during entry changes nothing and sets the ESC parm to True.  }
  12. { Whichever state is displayed at the point the user presses   }
  13. { Return is the Boolean value returned in VAR parm State.      }
  14. {                                                              }
  15. {     From: COMPLETE TURBO PASCAL 5.0  by Jeff Duntemann       }
  16. {    Scott, Foresman & Co., Inc. 1988   ISBN 0-673-38355-5     }
  17. {--------------------------------------------------------------}
  18.  
  19. PROCEDURE FlipField(X,Y         : Integer;
  20.                     VAR State   : Boolean;
  21.                     TrueString  : String30;
  22.                     FalseString : String30;
  23.                     VAR Escape  : Boolean);
  24.  
  25. VAR Blanker   : String80;
  26.     KeyStroke : 0..255;
  27.     WorkState : Boolean;
  28.     Ch        : Char;
  29.  
  30.  
  31.  
  32. PROCEDURE ShowState(NowState : Boolean);
  33.  
  34. BEGIN
  35.   GotoXY(X,Y); Write(Blanker);   { Erase the old label }
  36.   IF NowState THEN
  37.     BEGIN
  38.       GotoXY(X,Y);
  39.       Write(TrueString)   { Write TrueString for NowState = True }
  40.     END
  41.   ELSE
  42.     BEGIN
  43.       GotoXY(X,Y);
  44.       Write(FalseString);  { Write FalseString for NowState = False }
  45.     END
  46. END;
  47.  
  48.  
  49. BEGIN
  50.   Escape := False; Ch := Chr(0);
  51.   LowVideo;                                { Use highlighting }
  52.   FillChar(Blanker,SizeOf(Blanker),' ');   { Set up Blanker String }
  53.   WorkState:=State;                        { Temporary Boolean }
  54.   IF Length(TrueString)>Length(FalseString) THEN  { Adjust Blanker }
  55.     Blanker[0] := Chr(Length(TrueString)) ELSE    {  String for lengths }
  56.     Blanker[0] := Chr(Length(FalseString));       {  of meaning labels  }
  57.   ShowState(WorkState);                    { Display initial label }
  58.   REPEAT
  59.     WHILE NOT KeyStat(Ch) DO BEGIN {NULL} END;  { Calls KeyStat... }
  60.     KeyStroke := Ord(Ch);
  61.     IF KeyStroke = 27 THEN Escape := True ELSE
  62.       IF KeyStroke<>13 THEN WorkState := NOT WorkState;
  63.     ShowState(WorkState);
  64.   UNTIL (KeyStroke=13) OR Escape;          { ...until CR or ESC is pressed }
  65.   IF NOT Escape THEN State:=WorkState;     { Update State if CR }
  66.   NormVideo;
  67.   ShowState(State);     { Redisplay State in non-highlighted text }
  68. END;
  69.